package common.commands;

import model.AltaRicaConst;
import model.AltaRicaDomain;
import model.AltaRicaNode;

import common.AltaRicaModel;

public class CommandList implements ICommand {

	@Override
	public String getName() {
		
		return "list";
	}

	@Override
	public String getSynopsis() {
		
		return "list <nodes | domains | constants>";
	}

	@Override
	public CommandValue run(String arg) {
		
		if (arg.toUpperCase().equals("NODES")) {
			System.out.println("Defined AltaRica Nodes:");
			for (AltaRicaNode node : AltaRicaModel.getNodes()) {
				System.out.println(node.getName());
			}
			return CommandValue.OK;
		}
		
		if (arg.toUpperCase().equals("DOMAINS")) {
			System.out.println("Defined Domains :");
			for (AltaRicaDomain domain : AltaRicaModel.getDomains()) {
				System.out.println(domain.getName());
			}
			return CommandValue.OK;
		}
		
		if (arg.toUpperCase().equals("CONSTANTS")) {
			System.out.println("Defined Constants :");
			for (AltaRicaConst constant : AltaRicaModel.getConstants()) {
				System.out.println(constant.getId());
			}
			return CommandValue.OK;
		}
		
		System.out.println("Unknown type: " + arg);
		return CommandValue.KO;
	}

	@Override
	public String help() {
		
		return "Prints the list of elements of the specified type";
	}

}
